package com.meng.baselibrary;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2017/5/15.
 */

public class BasePresenterImpl<V> implements BasePresenter<V>{
    protected Reference<V> mViewRef;
    @Override
    public void attachView(V view) {
        mViewRef = new WeakReference<V>(view);
    }

    @Override
    public void detachView() {
        if(mViewRef != null){
            mViewRef.clear();
            mViewRef = null;
        }
    }

    @Override
    public V getView() {
        return mViewRef != null?mViewRef.get():null;
    }

    @Override
    public boolean isViewAttached() {
        return mViewRef != null && mViewRef.get() != null;
    }
}
